package com.codeduck.curator.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.recipes.cache.ChildData;
import org.apache.curator.framework.recipes.cache.CuratorCacheListener;

/**
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @createDate: 2022-05-18
 */
@Slf4j
public class ZkNodeEventListener implements CuratorCacheListener {
    @Override
    public void event(CuratorCacheListener.Type type, ChildData childData, ChildData childData1) {
        switch (type) {
            case NODE_CHANGED:
                log.info("############## node changed before && after ############");
                log.info("修改前的节点路径[{}]", childData.getPath());
                log.info("修改前的节点的数据[{}]", new String(childData.getData()));
                log.info("修改后的节点路径[{}]", childData1.getPath());
                log.info("修改后的节点的数据[{}]", new String(childData1.getData()));
                break;
            case NODE_CREATED:
                log.info("############## node created ############");
                log.info("新增节点路径[{}]", childData1.getPath());
                log.info("新增节点数据[{}]", new String(childData1.getData()));
                break;
            case NODE_DELETED:
                log.info("############## node deleted ############");
                log.info("删除节点路径[{}]", childData.getPath());
                log.info("删除节点数据[{}]", new String(childData.getData()));
                break;
            default:
                break;

        }
    }
}
